// pages/agreementCustomerBooking/agreementCustomerBooking.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:false,
    height: 0,
    list: [],
    pickerConfig: {                     // 时间筛选
      endDate: true,
      dateLimit: false,
      initStartTime: "2019-01-01",
      initEndTime: "2019-12-01",
      limitStartTime: "2000-01-01",
      limitEndTime: "2100-12-31"
    },
    begin_date: '',
    end_date: '',
    company_name: '',
    pagination: {
      page_start: 0, //搜索开始页码
      current_page: 0, //当前页码
      page_count: 0, //总页数
      page_size: 10, //每页数量
      total_count: 0 //总数量
    },
  },
  onDisplay(){
    this.setData({
      show: true
    })
  },
  onClose(){
    this.setData({
      show: false
    })
  },
  onChange(e){
    this.setData({
      company_name: e.detail.value
    })
  },
  formatDate(date) {
    date = [new Date(date.startTime), new Date(date.endTime)];
    return `${date[0].getFullYear()}/${date[0].getMonth() + 1}/${date[0].getDate()}-${date[1].getFullYear()}/${date[1].getMonth() + 1}/${date[1].getDate()}`;
  },
  onConfirm(event) {
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
      begin_date: parseInt(new Date(event.detail.startTime).getTime()/1000),
      end_date: parseInt(new Date(event.detail.endTime).getTime()/1000)
    });
  },
  searchData(){
    this.setData({
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      }
    })
    this.getData();
  },
  getData(){
    wx.showLoading()
    let pagination = this.data.pagination;
    pagination['page_start'] = pagination.current_page + 1;
    wx.$api.listProtocolLogistics({
      company_name: this.data.company_name,
      begin_date: this.data.begin_date,
      end_date: this.data.end_date,
      pagination: pagination
    }).then(res=>{
      wx.hideLoading();
      if(res.data.code == 200){
        if(this.data.pagination.current_page == 0){
          this.setData({
            list: res.data.data.list,
            pagination: res.data.data.pagination
          })
        }else{
          this.setData({
            list: this.data.list.concat(res.data.data.list),
            pagination: res.data.data.pagination
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: function(res) {
        let query = wx.createSelectorQuery(),
        height = res.windowHeight;
        query.select('.search').boundingClientRect(function (rect) {
          that.setData({
            height: height - rect.height + 'px'
          })
          console.log(that.data.height, 'mmmmmmmm')
        }).exec();
        that.getData();
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})